package com.geek.javase.ch11.work.bifunctionwork;

/*
 *@author wangpeng
 *2025/10/22 10:30
 *@description TODO
 */
/**
 * BiFunction<T, U, R>练习
 * 将String类型的姓名、Integer类型的年龄，转换成Person对象
 */
public class BiFunctionDemo {
    public static void main(String[] args) {
        BiFunction<String, Integer, Person> biFunction = (name, age) -> new Person(name, age);
        Person person = biFunction.transfer("张三", 20);
        System.out.println(person);
    }
}

@FunctionalInterface
interface BiFunction<T, U, R> {
    R transfer(T t, U u);
}


class Person{
    private String name;
    private int age;

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    public String toString() {
        return "Person{name = " + name + ", age = " + age + "}";
    }
}